package org.jeecg.modules.appuser.job;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.Date.DateUtil;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.UUIDGenerator;
import org.jeecg.modules.appuser.constant.LuckDrawConstant;
import org.jeecg.modules.appuser.entity.TbUserLuckdraw;
import org.jeecg.modules.appuser.entity.TbUserLuckdrawConfig;
import org.jeecg.modules.appuser.service.ITbUserLuckdrawConfigService;
import org.jeecg.modules.appuser.service.ITbUserLuckdrawService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 早上8点任务。打开任务
 * 20 点关闭任务
 * 0 点 关闭任务，并创建第二天的抽奖任务
 */
@Slf4j
public class OpenLuckDrawTask implements Job  {

    @Autowired
    private ITbUserLuckdrawService tbUserLuckdrawService;


    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        log.info("抽奖8：00  任务,dateTime:{}", DateUtils.now());
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("state", 2);
        queryWrapper.eq("luckdraw_type", 1);//每日抽奖
        queryWrapper.le("start_time", new Date());
        queryWrapper.ge("end_time", new Date());
        TbUserLuckdraw tbUserLuckdraw = tbUserLuckdrawService.getOne(queryWrapper);
        if(null!=tbUserLuckdraw){
            tbUserLuckdraw.setState(1);
            if(tbUserLuckdrawService.updateById(tbUserLuckdraw)){
                log.info("抽奖任开启,dateTime:{}", DateUtils.now());
            }
        }
    }

}
